<?php
namespace App\Controllers\Collect;
use App\Models\Collect\Collect;
/**
*	当前商品是否收藏
*/
class IsCollect extends \App\Libs\Base\BaseAction
{
	protected function beforeRun() {
         parent::beforeRun();
        // $this->needLogin = TRUE;
    }
	
	public function execute() {
		if( isset( $this->session->user ) ){
			$cid = $this->request->get('cid');
			$type = $this->request->get('type');
			$collect = Collect::find( array(
				' cid = :cid: and type = :type: and uid ='.$this->session->user->id,
				'bind' => array( 'cid'=> $cid , 'type'=>$type )
			) );
			if( empty( $collect ) ){
				return \App\Libs\Views\Json::view( 0 , '未收藏', ['iscollect'=>0]);
			}else{
				return \App\Libs\Views\Json::view( 0 , '已收藏', ['iscollect'=>1]);
			}
			
		}
		//返回成功数据
		return \App\Libs\Views\Json::view( 0 , '未收藏', ['iscollect'=>0]);
	}
}
